package com.heima.kafka.controller;

import cn.hutool.json.JSONUtil;
import com.heima.kafka.dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloController {
    @Autowired
    KafkaTemplate<String,String> kafkaTemplate;
    @GetMapping("/hello")
    public String hello(){
        kafkaTemplate.send("kafkaTest","hello world");
        return "hello";
    }
    @GetMapping("/user")
    public String user(@RequestBody UserDto dto){
        kafkaTemplate.send("kafkaTestUser", JSONUtil.toJsonStr(dto));
        return "hello";
    }
}
